package com.myx.service.user;

import com.myx.dao.user.UserDao;
import com.myx.dao.user.UserDaoImpl;
import com.myx.pojo.User;

public class UserServiceImpl implements UserService {
    public UserDao userDao=new UserDaoImpl();


    @Override
    public boolean addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public boolean isExistUsername(String username) {
        int count = userDao.verifyOnlyUsername(username);
        return count == 1;
    }

    public User getUserByUsernameAndPassword(String username, String password){
        User userByUsername = userDao.getUserByUsername(username);
        if (userByUsername!=null){
            if (userByUsername.getPassword().equals(password)) {
                return userByUsername;
            }
        }
        return null;
    }

    @Override
    public User getUserById(Integer createById) {
        return this.userDao.getUserById(createById);
    }

    @Override
    public User getAdminUserByUsernameAndPassword(String username, String password) {
        User userByUsername = this.userDao.getUserByUsername(username);
        if (userByUsername != null&&userByUsername.getPassword().equals(password)&&(userByUsername.getUserType()==0)) {
            return userByUsername;
        }else {
            return null;
        }

    }
}
